﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class message_details : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            //cldrDateStart.SelectedDate = DateTime.Today.AddDays(-1);
            //cldrDateStart.VisibleDate = DateTime.Today;
            if (Context.Request.QueryString["id"] != null)
            {
                dsMsgHistory.SelectParameters["MsgID"].DefaultValue = Context.Request.QueryString["id"];
                dsMsgHistory.SelectParameters["FromCode"].DefaultValue = Context.Request.QueryString["from"];
                dsMsgHistory.SelectParameters["ToCode"].DefaultValue = Context.Request.QueryString["to"];
                try
                {
                    gvMsgHistory.DataBind();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                //lbtnCard.Text = "Карточка абонента - " + Context.Request.QueryString["surname"];
                gvMsgHistory.Sort("SendTime", SortDirection.Ascending);
                // возьмем данные из таблы мон400
                //string MonCode = "x400 address";
                SqlConnection sqlconn = new SqlConnection(dsMsgHistory.ConnectionString);
                string sqlQuery = "select x400 from mon400_abonents where surname = @id";
                SqlCommand sqlcomm = new SqlCommand(sqlQuery, sqlconn);
                // set parameters
                sqlcomm.Parameters.Add("@id", SqlDbType.VarChar);
                sqlcomm.Parameters["@id"].Value = Context.Request.QueryString["from"]; ;
                try
                {
                    sqlconn.Open();
                    lbApFrom.Text = lbApFrom.Text + (String)sqlcomm.ExecuteScalar();
                    sqlconn.Close();
                    //sqlcomm.Dispose();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            };
            Title = "История прохождения сообщения - " + Context.Request.QueryString["id"];
        };
    }
    protected void dsMsgHistory_Selected(object sender, SqlDataSourceStatusEventArgs e)
    {
        //beep;
    }
}